package nl.dxn.tunnel.server;

import io.netty.channel.Channel;
import io.netty.util.AttributeKey;
import nl.dxn.tunnel.server.cache.AgentChannelDto;

import java.io.File;
import java.net.URL;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.util.HashMap;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class Constants {
    public static final AttributeKey<AgentChannelDto> PROXY = AttributeKey.newInstance("PROXY");
    public static final AttributeKey<String> SERVER_ID = AttributeKey.newInstance("SERVER_ID");
    public static final AttributeKey<HashMap<String, Channel>> CLIENT_MAP = AttributeKey.newInstance("CLIENT_MAP");

    public static String getContextPath()
    {
        ProtectionDomain protectionDomain = Constants.class.getProtectionDomain();
        CodeSource codeSource = protectionDomain.getCodeSource();
        URL location = codeSource.getLocation();
        File codeSourceFile = new File(location.getPath());
        return codeSourceFile.getParent();
    }
}
